package states;

import hypeerweb.Node;
import hypeerweb.Range;

/**
 * The Cap state, sets the higher range to 0 (the insertion node)
 * and moves to the Terminal state.
 *
 * @author brinkerhoff_kendra
 *
 */
public class HypercubeCapNodeState extends NodeState {

	/**
	 * Default constructor, sets the current state of the machine.
	 */
	public HypercubeCapNodeState() {
		STATE_ID = 3;
	}

	/**
	 * Replaces range.upperBound the node with webid 0.  
	 * 
	 * @pre range &ne; null AND
	 * 		<br>lowerBound is a cap node with fold 0
	 * @post result = TerminalNodeState where upperBound' = lowerBound.fold
	 */
	public final NodeState shrinkRange(final Range r) {
		range = r;

		// We are guaranteed that the fold of the lower
		// bound is 0 if we reach this state
		Node lower = range.getLowerBound();
		range.setUpperBound(lower.getFold());

		return new TerminalNodeState();
	}

	/**
	 * @return "Hypercube Cap State"
	 */
	public final String toString() {
		return "Hypercube Cap State";
	}
}
